import { mapGetters } from 'vuex'

export default {
	computed: {
		...mapGetters('module_cart', ['total'])
	},
	watch: {
		total() {
			this.setBadge()
		}
	},
	onShow() {
		this.setBadge()
	},
	methods: {
		setBadge() {
			if (this.total > 0) {
				uni.setTabBarBadge({
					index: 2,
					text: String(this.total),
					// complete(e) {
					// 	console.log(e)
					// }
				}).catch(e => e)
			} else {
				uni.hideTabBarRedDot({
					index: 2
				})
			}
		}
	}
}